package com.wiloon.java8x.basic;

import java.io.Console;

/**
 * Created by wiloon on 4/5/17;
 */
public class ConsoleTest {

    public static void main(String[] args) {
        Console console = System.console();//获得Console实例
        if (console != null) {//判断console是否可用
            String user = new String(console.readLine("Enter user:")); //读取整行字符
            String pwd = new String(console.readPassword("Enter passowrd:")); //读取密码,密码输入时不会显示
            console.printf("User is:" + user + "\n");
            console.printf("Password is:" + pwd + "\n");
        } else {
            System.out.println("Console is unavailable");
        }
    }
}